package day24.edu;

import org.junit.Test;

import java.lang.reflect.Array;
import java.util.*;

// Created: 24/09/2025, ChangJiang Ru
public class Exer1 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(11);
        arrayList.add(22);
        arrayList.add(11);
        arrayList.add(11);
        arrayList.add(22);
        arrayList.add(33);
        arrayList.add(44);
        arrayList.add(22);

        /*
        for(Object obj: arrayList)
        {
            System.out.print(obj);
//            System.out.println();
        }
        System.out.println();

        List newList = duplicateList(arrayList);

        for (Object obj : newList)
        {
            System.out.print(obj);
        }

         */

        System.out.println(arrayList);
        List newList = duplicateList(arrayList);
        System.out.println(newList);

    }

    public static List duplicateList(List list)
    {
        // Case 1:
        /*
        HashSet hashSet = new HashSet();
        for (Object obj : list)
        {
            hashSet.add(obj);
        }

        ArrayList arrayList = new ArrayList();
        for (Object obj : hashSet)
        {
            arrayList.add(obj);
        }

        return arrayList;

         */

        // Case 2:
        HashSet set = new HashSet(list);
        ArrayList list1 = new ArrayList(set);
        return list1;
    }
    
    @Test
    public void test1() {
        Set set = new HashSet();

        int count = 0;
        while(set.size() < 10)
        {
            int random = (int)(Math.random() * (20 - 1 + 1) + 1);
            set.add(random);
            count++;
        }

        Iterator iterator = set.iterator();
        while(iterator.hasNext())
        {
            System.out.println(iterator.next());
        }

        System.out.println("========");
        System.out.println(count);
    }
    
    @Test
    public void test2()
    {
        HashSet set = new HashSet();
        User u1 = new User("Tome", 12);
        User u2 = new User("Jerry", 45);
        set.add(u1);
        set.add(u2);
        System.out.println(set);
    }
}
